package com.leetcode.partition7;

import com.leetcode.common.TreeNode;

/**
 * @author `RKC`
 * @date 2021/8/20 9:19
 */
public class LC700二叉搜索树中的搜索 {

    public static TreeNode searchBST(TreeNode root, int val) {
        return recursion(root, val);
    }

    private static TreeNode iteration(TreeNode root, int value) {
        while (root != null) {
            if (root.val > value) root = root.left;
            else if (root.val < value) root = root.right;
            else return root;
        }
        return null;
    }

    private static TreeNode recursion(TreeNode root, int value) {
        if (root == null) return null;
        if (root.val > value) return recursion(root.left, value);
        if (root.val < value) return recursion(root.right, value);
        return root;
    }
}
